package SwordFingerOffer;

public class Q16_Pow {

    //快速幂
    public static double myPow(double x, long n) {

        if(n < 0){
            double ans = process(x, -n);
            return 1.00000 / ans;
        }
        return process(x, n);
    }



    public static double process(double x, long n){
        if (n == 0)
            return 1;
        //奇数
        else if (n % 2 == 1)
            return myPow(x, n - 1) * x;
        else
            //偶数
        {
            double temp = myPow(x, n / 2);
            return temp * temp;
        }
    }



    public static void main(String[] args) {
        System.out.println(myPow(2.00000
                ,2147483648L));
    }
}
